<div class="layuimini-container">
    <form id="app-form" class="layui-form layuimini-form">
        
        <div class="layui-form-item">
            <label class="layui-form-label">分类标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" class="layui-input" lay-verify="required" placeholder="请输入标题" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分类类别</label>
            <div class="layui-input-block">
                <select name="type" lay-verify="required" lay-filter="type">
                    {foreach $cate_type_list as $key => $vo}
                    <option value="{$key}">{$vo}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-form" lay-filter="_pid">
            <label class="layui-form-label">上级分类</label>
            <div class="layui-input-block" >
                <select id="pid" name="pid">
                    <option value="0">顶级分类</option>
                    {foreach $cate_tree_list as $vo}
                        <option value="{$vo.id}" >{$vo.title|raw}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="hr-line"></div>
        <div class="layui-form-item text-center">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit>确认</button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">重置</button>
        </div>

    </form>
</div>

<script id="cate_pid" type="text/html">
    <option value="0">顶级分类.</option>
    {{#  layui.each(d.list, function(index, item){ }}
    <option value="{{item.id}}">{{ item.title }}</option>
    {{#  }); }}
</script>
<script>

    layui.use(['form', 'layer', 'laytpl'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var laytpl = layui.laytpl;

        form.on('select(type)', function(data){
            $('#pid').html('');
            let id = data.value;
            $.ajax({
                url:"getTree",
                data:{'type_id':id},
                type:"Post",
                dataType:"json",
                success:function(data){
                    console.log(data.data);
                    var str = laytpl(cate_pid.innerHTML).render({'list': data.data});
                    $('#pid').html(str);
                    form.render('select', '_pid');
                },
                error:function(data){
                    $.messager.alert('错误',data.msg);
                }
            });
        });
    });
</script>